local skel = fk.CreateSkill {
  name = "lb__taxing",
  max_branches_use_time = {
    ["round"] = {
      [Player.HistoryRound] = 1
    },
  }
}

Fk:loadTranslationTable {
  ["lb__taxing"] = "坍星",
  --[":lb__taxing"] = "其他角色的回合开始时，你可以令其进行三次判定，若有连续出现的颜色，你视为对其使用连续颜色数张【杀】。",
  --10.2
  [":lb__taxing"] = "每轮限一次，其他角色的回合开始时，你可以令其进行四次判定，若有连续出现的颜色，你视为对其使用连续颜色数张【杀】。",

  ["#lb__taxing"] = "坍星：你可以令%dest进行四次判定，若有连续出现的颜色，你视为对其使用连续颜色数张【杀】",

  ["$lb__taxing1"] = "",
  ["$lb__taxing2"] = "",
}

skel:addEffect(fk.TurnStart, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target ~= player and target:isAlive()
        and player:usedSkillTimes(skel.name, Player.HistoryRound, "round") == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#lb__taxing::" .. target.id, })
  end,
  on_use = function(self, event, target, player, data)
    player:addSkillBranchUseHistory(skel.name, "round")
    local room = player.room
    local list = {}
    for i = 1, 4, 1 do
      local judge = {
        who = target,
        pattern = ".",
        reason = skel.name,
      }
      room:judge(judge)
      table.insert(list, judge.card.color)
    end
    local function findMostConsecutiveAll(numbers)
      if #numbers == 0 then
        return {}, 0
      end

      local current_num = numbers[1]
      local current_count = 1
      local max_count = 1
      local result_nums = { current_num }

      for i = 2, #numbers do
        if numbers[i] == current_num then
          current_count = current_count + 1
        else
          -- 检查当前连续序列
          if current_count > max_count then
            max_count = current_count
            result_nums = { current_num }
          elseif current_count == max_count then
            table.insert(result_nums, current_num)
          end
          -- 开始新的连续序列
          current_num = numbers[i]
          current_count = 1
        end
      end

      -- 检查最后一个连续序列
      if current_count > max_count then
        return { current_num }, current_count
      elseif current_count == max_count then
        table.insert(result_nums, current_num)
      end

      return result_nums, max_count
    end
    local _, num = findMostConsecutiveAll(list)
    if num > 1 then
      for i = 1, num, 1 do
        if player.dead or target.dead then
          break
        end
        room:useVirtualCard("slash", nil, player, target, skel.name, true)
      end
    end
  end,
}, { check_skill_limit = true})

return skel
